<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 输入：[1, 2, 4, 4, 3, 3, 1, 5, 3]
      // 输出：[1, 3, 4]
      let arr = [1, 2, 4, 4, 3, 3, 1, 5, 3];
      function duplicates(arr) {
        var newArr = []; 
        var arrRepeat = [];
        arr.forEach((item) => {
          if (newArr.indexOf(item) == -1) {
            newArr.push(item);
          } else {
            arrRepeat.push(item);
          }
        });
        return [...new Set(arrRepeat)].sort();
      }
      console.log(duplicates([1, 2, 4, 4, 3, 3, 1, 5, 3]));
    </script>
  </body>
</html>
